import 'dart:convert';
import 'dart:io';
import 'package:base_lib/common/network/net.dart';
import 'package:base_lib/common/network/result_body.dart';
import 'package:base_lib/config.dart';
import 'package:base_lib/index.dart';
import 'package:base_lib/repository/file_net_intercept.dart';
import 'entity/upload_file_entity.dart' as UploadBean;

class FileHttp {
  static HttpManager _httpProxyIns;

  static createHttpProxy(
      {mBaseUrl = Config.fileBaseUrl,
      codeName = Config.codeName,
      codeSuccessValue = Config.codeSuccessValue,
      msgName = Config.msgName,
      reqTimeOut = Config.reqTimeOut,
      respTimeOut = Config.respTimeOut,
      logTag = "file"}) {
    _httpProxyIns = HttpManager(mBaseUrl,
        CODE_NAME: codeName,
        CODE_SUCCESS_VALUE: codeSuccessValue,
        MSG_NAME: msgName,
        REQ_TIME_OUT: reqTimeOut,
        RESP_TIME_OUT: respTimeOut,
        LOG_TAG: logTag,
        defaultInterceptors: [FileNetIntercept()]);
  }

  /// 上传/下载文件
  static const String INTERFACE_FILE_LOAD = "api/sys/file";

  /// 批量获取文件信息
  static const String INTERFACE_FILE_LIST_GET = "api/sys/filelist";

  ///上传文件
  static Future<ResultBody<UploadBean.Data>> upload(Map<String, File> files,
      {Map<String, String> params}) {
    return _httpProxyIns.upload<UploadBean.Data>(
      INTERFACE_FILE_LOAD,
      (resMap) => UploadBean.UploadFileEntity.fromJson(resMap).data,
      files,
      params: params,
    );
  }
}
